// 翻滚加载(热搜部分)
// 思路;向下翻滚，页数加一，请求发送一次，渲染一次
var currentPage = 1;
// 判断数据是否为0
var url;

function getrestMsg() {
  $(window).scroll(function () {
    if (
      Math.round($(window).scrollTop() + $(window).height()) ==
      $(document).height()
    ) {
      currentPage++;
      $.ajax({
        url: `/weibo/user/getLoadedReportForUser?pageNo=${currentPage}&pageSize=10`,
        type: "get",
        data: {},
        success: function (result) {
          let allnews = document.querySelector("#news");
          let user = getInfo();
          for (let i = 0; i < result.length; i++) {
            //   判断是赞评论还是赞文章
            let report = result[i];

            if (!result[i].blogUrl) {
              url = result[i].userUrl;
            } else {
              url = result[i].blogUrl;
            }

            if (user.id != report.uid) {
              allnews.innerHTML += `
              <div class="news add" >
              <div class="message-top">
                <div class="top-details">
                  <p class="time" >${report.time}</p>
                </div>
              </div>
              <div class="message-content" >
                <p>经审核,该博文因违规而不被推荐</p>
                <p class="tip-off-reason">
                  违规原因：<span >${report.msg}</span>
                </p>
              </div>
              <div class="message-content" th:unless="${session.id}!=${report.uid}">
                <p>经审核,你举报的博文确实存在违规行为，已进行相应处罚</p>
              </div>
              <div class="message-container">
                <div class="message-content-img">
                  <img
                   
                    src=""${url}
                    alt=""
                  />
                  
                </div>
                <div class="message-content-text">
                  <!--                                <p><span>@</span><span >${report.text}</span></p>-->
                  <p  class="message-content-blog">${report.text}</p>
                </div>
              </div>
            </div>
                `;
            } else if (user.id == report.uid) {
              let state = report[i].state;
              let text;
              if (state == 0) {
                text = `<p>经审核,举报理由与文章内容不符，已驳回</p>`;
              } else if (state == 1) {
                text = `<p>经审核,你举报的博文确实存在违规行为，已进行相应处罚</p>`;
              } else if (state == 2) {
                text = `<p>你的举报正在审核中...</p>`;
              }
              allnews.innerHTML +=
                `
                <div class="news add" >
                <div class="message-top">
                  <div class="top-details">
                    <p class="time" >${report.time}</p>
                  </div>
                </div>
                
                <div class="message-content" >
                 ` +
                `${text}` +
                `
                </div>
                <div class="message-container">
                  <div class="message-content-img">
                    <img
                     
                      src="${url}"
                      alt=""
                    />
                    
                  </div>
                  <div class="message-content-text">
                    <!--                                <p><span>@</span><span >${report.text}</span></p>-->
                    <p  class="message-content-blog">${report.text}</p>
                  </div>
                </div>
              </div>
                  `;
            }
          }
          if (result.length > 0 && result.length < 10) {
            allnews.innerHTML += `<p class="none">暂时没有其他内容了</p>`;
          }
          switchoverfn();
        },
      });
    }
  });
}
getrestMsg();
